//
//  XMTabBer.m
//  Second
//
//  Created by Alex on 16/7/13.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "XMTabBer.h"
@interface XMTabBer ()
@property (nonatomic,weak)UIButton *publishButton;

@end

@implementation XMTabBer
- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
        UIButton *publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        publishButton.size = CGSizeMake(60, 60);
        [publishButton addTarget:self action:@selector(PubAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:publishButton];
        self.publishButton = publishButton;
        
        
        
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.publishButton.center = CGPointMake(self.width * 0.5, self.height * 0.5);
    CGFloat buttinY = 0;
    CGFloat buttinW = self.width / 5;
    CGFloat buttinH = self.height;
    NSInteger index = 0;
    for (UIView *button in self.subviews) {
        if (![button isKindOfClass:NSClassFromString(@"UITabBarButton")])continue;
        
        CGFloat buttinX = buttinW * ((index > 1) ? (index + 1) : index);
        
        button.frame = CGRectMake(buttinX, buttinY, buttinW, buttinH);
        index++;
    }
}

- (void)PubAction {
    
    XMPublishViewController *publish = [[XMPublishViewController alloc]init];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:publish animated:YES completion:^{
        
    }];
    
    
   
}




@end
